local Lua__huoyanjinjing = fk.CreateSkill {
  name = "Lua__huoyanjinjing",
  anim_type = "control",
}

Fk:loadTranslationTable {
  ["Lua__huoyanjinjing"] = "火眼金睛",
  ["#Lua__huoyanjinjing"] = "你可观看一名目标手牌，并弃置一种花色的手牌。",
  [":Lua__huoyanjinjing"] = "出牌阶段限一次，你可观看一名目标手牌，并弃置一种花色的手牌。若累计弃置四种花色。可选择一项：1：可任选一名目标翻面。并对其造成三火焰伤害；2额外获得一回合。",
  ["#Lua__huoyanjinjing-obtain"] = "火眼金睛：选择弃置 %src 的一种花色的手牌",
  ["hyjj1"] = "令一名角色翻面，并对其造成三火焰伤害",
  ["hyjj2"] = "获得一个额外的回合",
  ["@Lua__huoyanjinjing"] = "火眼金睛",
  ["#Lua__huoyanjinjing-target"] = "火眼金睛：选择一名角色其翻面，你对其造成3点火焰伤害。",
}


Lua__huoyanjinjing:addEffect("active", {
  prompt = "#Lua__huoyanjinjing",

  can_use = function(self, player)
    return player:usedSkillTimes(Lua__huoyanjinjing.name, Player.HistoryPhase) == 0
  end,

  card_filter = Util.FalseFunc,

  target_filter = function(self, player, to_select, selected, cards)
    return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
  end,
  target_num = 1,

  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    -- 获取目标的手牌
    local cards = target.player_cards[Player.Hand]
    local availableCards = table.filter(cards, function(id)
      return true
    end)
    local get = room:askToChooseCardsAndChoice(player, {
      cards = availableCards,
      choices = { "OK" },
      skill_name = self.name,
      prompt = "#Lua__huoyanjinjing-obtain",
      cancel_choices = nil,
    })
    if #get > 0 then
      local card_names = {}
      for _, id in ipairs(target:getCardIds("h")) do
        if Fk:getCardById(id).suit == Fk:getCardById(get[1]).suit then
          table.insert(card_names, id)
        end
      end
      if #card_names > 0 then
        local dummy = Fk:cloneCard("dilu")
        dummy:addSubcards(card_names)
        room:throwCard(dummy, Lua__huoyanjinjing.name, target, player)
      end
      if not table.contains(player:getTableMark("@Lua__huoyanjinjing"), Fk:getCardById(get[1]):getSuitString(true)) then
        player.room:addTableMark(player, "@Lua__huoyanjinjing", Fk:getCardById(get[1]):getSuitString(true))
      end
    end
    if #player:getTableMark("@Lua__huoyanjinjing") >= 4 then
      room:setPlayerMark(player, "@Lua__huoyanjinjing", 0)
      local choice = player.room:askToChoice(player, {
        choices = { "hyjj1", "hyjj2" },
        skill_name = Lua__huoyanjinjing.name,
      })
      if choice == "hyjj1" then
        local targets = room:askToChoosePlayers(player, {
          targets = room:getAlivePlayers(),
          min_num = 1,
          max_num = 1,
          skill_name = Lua__huoyanjinjing.name,
          prompt = "#Lua__huoyanjinjing-target",
          cancelable = false,
        })
        targets[1]:turnOver()
        room:damage({
          from = player,
          to = targets[1],
          damage = 3,
          damageType = fk.FireDamage,
          skillName = Lua__huoyanjinjing.name
        })
      else
        player:gainAnExtraTurn(true, Lua__huoyanjinjing.name)
      end
    end
  end,
})

return Lua__huoyanjinjing
